package com.dulich.fragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

public class CentralFragmentActivity extends FragmentActivity {
	int ROOT_VIEW_ID;
	
	protected void setRootView(int id) {
		ROOT_VIEW_ID = id;
	}

	public int getRootView() {
		return ROOT_VIEW_ID;
	}

	// mo mot fragment
	public void openFragment(Fragment fragment) {
		getSupportFragmentManager().beginTransaction().replace(ROOT_VIEW_ID, fragment).addToBackStack(null).commit();
	}

	// dong mot fragment
	public void closeFragment(Fragment fragment) {
		getSupportFragmentManager().beginTransaction().remove(fragment).commit();
		getSupportFragmentManager().popBackStack();
	}

	// nhan nut back trong fragment
	@Override
	public void onBackPressed() {
		if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
			getSupportFragmentManager().popBackStack();
			return;
		}
		finish();
	}
	
}
